package com.linwen.javase.juc.threadPool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName _02MyThreadPool
 * @Description
 * @Author lin
 * @Date 2022/4/24 下午11:27
 * @Version V1.0
 *
 * 自定义线程池，需要熟知七大核心参数
 */
public class _02MyThreadPool {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 10, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());

        for (int i = 0; i < 2000; i++) {
            int finalI = i;
            threadPoolExecutor.execute(()->{
                System.out.println(Thread.currentThread().getName()+"  working  "+ finalI);
            });
        }

        threadPoolExecutor.shutdown();

    }
}
